import tensorflow as tf
import os
import numpy as np

if __name__ == '__main__':
    # 设置 TensorFlow 的运行日志等级为 2 ---Warning
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

    c1 = tf.constant(123)
    c2 = tf.constant(456)

    r = tf.add(c1, c2)
    print(r)

    # 直接使用 + 运算符
    r1 = c1 + c2
    print(r1)

    r2 = tf.math.add(c1, c2)
    print(r2)

    x = [1, 2, 3]
    y = 4

    # python 语言不支持
    # print(x + y)

    # 以广播的形式进行运算
    z = tf.math.add(x, y)
    print(z)

    x1 = tf.convert_to_tensor(x)
    y1 = tf.convert_to_tensor(y)

    z1 = x1 + y1
    print(z1)

    m = tf.constant([1,2,3], dtype=tf.int32)
    n = tf.constant([1,2,3], dtype=tf.float64)

    # 张量的类型必须相同，
    # l = m + n
    # print(l)

    # 当输入一个为张量，另外一个不是张量。非张量类型会转到张量类型在进行计算。
    u = tf.constant([1, 2, 3], dtype=tf.int8)
    v = [126,126,126]
    print(u + v)

    print(np.ones(6))
    print(np.ones(6).reshape(1,2,1,3))

    a = np.ones(6).reshape(1,2,1,3)
    b = np.ones(6).reshape(2,1,3,1)

    # print(a + b)
    print(tf.add(a, b).shape.as_list())



